home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / ead / ead17.dms / ead17.adf / Listati / clips.c < prev    next >
C/C++ Source or Header  |  1989-08-01  |  4KB  |  155 lines

  1. /**************************************************************************
  2.  
  3.  Clips.c - Testo sorgente in linguaggio C di pubblico dominio - 
  4.  
  5.  Trasferisce in RAM un file ASCII per il trattamento con editor AmigaBASIC
  6.  
  7. ---------------------------------------------------------------------------
  8.  
  9.              Scritto da Paolo Bozzo - Via Bolzano, 23 - Milano
  10.  
  11.              Ringraziamenti a Luigi Callegari per la revisione
  12.  
  13.                  (Versione 1.1 - gira anche da WorkBench)
  14.  
  15. ---------------------------------------------------------------------------
  16.  
  17. Compilazione Lattice V5.0: 
  18. lc -v -cw Clips
  19. Blink lib:c.o clips.o LIB lib:lc.lib lib:amiga.lib DEFINE __main __tinymain SC SD ND
  20.  
  21. Compilazione Aztec C V3.6: cc +L Clips ------ ln clips c32.lib
  22.  
  23.  
  24. ***************************************************************************/
  25.  
  26. #include <exec/types.h>
  27. #include <libraries/dosextens.h>
  28. #include <workbench/startup.h>
  29. #include <ctype.h>
  30.  
  31. #ifndef AZTEC_C
  32. #include <proto/dos.h>
  33. #include <proto/exec.h>
  34. #include <string.h>
  35. #else
  36. #include <functions.h>
  37. #endif
  38.  
  39. #define  RETURN   '\r'
  40. #define  NEWLINE  '\n'
  41. #define  MAXWINDOW 40
  42.  
  43. struct FileHandle *finestra;
  44.  
  45. void print(s)    /* stampa una stringa */
  46. char*s;
  47. {
  48.     Write((BPTR)finestra, s, strlen(s));
  49. }
  50.  
  51. void  main (argc,argv)
  52. int   argc;
  53. char  **argv;
  54. {
  55. register struct WBArg       *argomento;
  56. register struct Lock        *indirizzo_dir;
  57. struct FileHandle           *infile, *outfile;
  58. register LONG               mia_dir=0;
  59. register UBYTE              buffer[512];
  60. register int                lung, i;
  61. UBYTE                       *io, *file;
  62. int                         args_number;
  63. static char             window[MAXWINDOW+18];
  64.  
  65. infile = outfile = NULL; /* evita spiacevoli visite */
  66.  
  67. if ( argc == 0 )  /* se lanciato da WorkBench */
  68.    {
  69.    argomento = ((struct WBStartup *)argv) -> sm_ArgList;
  70.    io = (UBYTE *) argomento[0].wa_Name;           /*nome di clips*/
  71.    args_number = ((struct WBStartup *)argv) -> sm_NumArgs;    /*numero argomenti WB*/
  72.    strcpy(window, "con:10/10/320/80/");
  73.    strncat(window, io, MAXWINDOW);
  74.    finestra = (struct FileHandle *)Open(window,MODE_NEWFILE);
  75.    if (args_number != 2)
  76.       {
  77.       print( " USO: \n un click sull'icona di ");
  78.         print( io);
  79.       print( "\n SHIFT + due click su quella  del\n");
  80.       print( " file ASCII da trasferire.\n");
  81.       goto fine;
  82.       } 
  83.    file = (UBYTE *)argomento[1].wa_Name;          /*nome file ASCII*/     
  84.    indirizzo_dir = (struct Lock *)argomento[1].wa_Lock;
  85.    mia_dir = CurrentDir((BPTR)indirizzo_dir);       /*cambio directory*/
  86.    }
  87. else /* se lanciato da CLI */
  88.    {
  89.    io = argv[0];                             /*nome di clips*/
  90.    finestra = (struct FileHandle *)Output(); /*finestra CLI */
  91.    if (argc == 2)
  92.       file = argv[1];       /*nome file ASCII*/
  93.    else 
  94.       {
  95.       print( "Sintassi: ");
  96.       print( io);print( " nome_file\n");
  97.       goto fine;
  98.       }
  99.    }
  100.  
  101. if ( ! ( infile = (struct FileHandle *)Open( (char *) file, MODE_OLDFILE)) )
  102.    {
  103.    print( " errore: file non trovato.\n");
  104.    goto fine;
  105.    }
  106.  
  107. lung = Read((BPTR)infile, buffer, 512);
  108.  
  109. for ( i = 0; i < 8; i++ )
  110.     {
  111.     if ( ! ( isascii( buffer[i]) )) /* se i primi byte non sono ASCII */
  112.         {
  113.         print( " Il file selezionato non è ASCII!\n");
  114.         goto fine;
  115.         }
  116.     }
  117.  
  118. if ( ! (outfile = (struct FileHandle *)Open("ram:BasicClip",MODE_NEWFILE)))
  119.     {
  120.     print( " operazione fallita.\n");
  121.     goto fine;
  122.     }
  123.  
  124. /* Questa è la parte centrale */
  125.  
  126. do
  127.    {
  128.     for ( i = 0; i < lung; i++ )
  129.         if ( buffer[i] == NEWLINE)
  130.              buffer[i] = RETURN;
  131.    Write((BPTR)outfile, buffer,lung);
  132.    }
  133.    while ( (lung=Read((BPTR)infile, buffer,512))!=0);
  134.  
  135. print( " operazione conclusa!\n");
  136.  
  137. fine:
  138. if (mia_dir) CurrentDir(mia_dir);
  139. if (infile)  Close((BPTR) infile);
  140. if (outfile) Close((BPTR) outfile);
  141. if (argc==0)
  142.     {
  143.         print( "\n Premere RETURN");
  144.         while (Read((BPTR)finestra,file,1),*file!='\n');
  145.         Close ((BPTR) finestra);
  146.     }
  147. }
  148.  
  149. #ifndef AZTEC_C
  150. void MemCleanup() {}
  151. #endif
  152.  
  153. /* ******************************* FINE DEL FILE ************************* */
  154.  
  155.